<?php
include 'mainfile.php';



if(isset($_POST['permission'])){

    $perm = 0;
    echo '<pre>';
    
    print_r($_POST['permission']);
    
    
    foreach ($_POST['permission'] as $val) {
        $perm = $perm | $val;
    }
    echo '<br />';
    if(true) {
        $user_permission = $perm;

        if($user_permission & 1)
        {
            echo 'duoc quyen VIEW';        
        } else {
            echo 'khong duoc quyen View';
        }
        
        echo '<br />';

        if($user_permission & 2){
            echo 'duoc quyen ADD';

        } else {
            echo 'khong duoc quyen ADD';
        }
        
        echo '<br />';

        if($user_permission & 4){
            echo 'duoc quyen EDIT';
        } else {
            echo 'khong duoc quyen EDIT';
        }
        
        echo '<br />';
        
        if($user_permission & 8){
            echo 'duoc quyen DELETE';
        } else {
            echo 'khong duoc quyen DELETE';
        }
        
        echo '<br />';
        
        if($user_permission & 16){
            echo 'duoc quyen Admin';
        } else {
            echo 'Khong co quyen Admin';
        }
    }
    
    echo '<br />';
    
    print_r($perm);
    echo '</pre>';

}
?>


<form name="test" method="POST">
    <input type="checkbox" name="permission[]" value="1" /> LIST <br />
    <input type="checkbox" name="permission[]" value="2" /> ADD  <br />
    <input type="checkbox" name="permission[]" value="4" /> EDIT <br />
    <input type="checkbox" name="permission[]" value="8" /> DELETE <br />
    <input type="checkbox" name="permission[]" value="31" /> ADMIN <br />
    <input type="submit" value="SUBMIT" name="submit" />
</form>